package com.itheima.listener;

import com.heima.model.wemedia.pojos.WmNews;
import com.itheima.service.WmNewsService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author yunfei
 * @date 2022年10月20日 15:50
 */
@Component
public class RabbitMQListener {

    @Autowired
    private WmNewsService wmNewsService;

    @RabbitListener(queues = "wmnews_delay_queue")
    public void handlerMsg(Integer newsId) {
        // 根据id查询一个wmnews对象
        WmNews wmNews = wmNewsService.getById(newsId);
        // 调用发布的方法
        wmNewsService.publishNewsToArticle(wmNews);
        System.out.println("MQ中接收的文章id:" + newsId);
    }

}
